﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using EntityBinder.Interface;

namespace EntityBinder
{
	public static class EntityReaderFactory
	{
		#region GetReader factory

		public static IEntityReader GetReader(EntityBinderFormat _format)
		{
			if(_format == EntityBinderFormat.XML)
			{
				return new Xml.XmlReader();
			}
			else if(_format == EntityBinderFormat.JSON)
			{
				return new Json.JsonReader();
			}

			throw new EntityBinderException("EntityReaderFactory", "GetReader", "Unable to return a Reader for format " + _format);
		}

		public static IEntityReader GetReader(EntityBinderFormat _format, IEntityElement _rule)
		{
			if (_format == EntityBinderFormat.XML)
			{
				return new Xml.XmlReader(_rule);
			}
			else if (_format == EntityBinderFormat.JSON)
			{
				return new Json.JsonReader(_rule);
			}

			throw new EntityBinderException("EntityReaderFactory", "GetReader", "Unable to return a Reader for format " + _format);
		}

		public static IEntityReader GetReader(EntityBinderFormat _format, IEnumerable<IEntityElement> _rules)
		{
			if (_format == EntityBinderFormat.XML)
			{
				return new Xml.XmlReader(_rules);
			}
			else if (_format == EntityBinderFormat.JSON)
			{
				return new Json.JsonReader(_rules);
			}

			throw new EntityBinderException("EntityReaderFactory", "GetReader", "Unable to return a Reader for format " + _format);
		}

		public static IEntityReader GetReader(EntityBinderFormat _format, params Type[] _readableTypes)
		{
			return GetReader(_format, EntityRulesFactory.GetRules(_readableTypes));
		}

		public static IEntityReader GetReader<T>(EntityBinderFormat _format)
		{
			return GetReader(_format, EntityRulesFactory.GetRules<T>());
		}

		#endregion
	}
}
